package window;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import model.Topic;

public class Window extends JFrame implements ActionListener {
	JDesktopPane desktop; 
	TopicFrame tframe; 
	public Window(){
		super("ReportViz");
		//setSize(800, 600);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		init();
	}
	int view_width, view_height; 
	private void init(){
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int inset = 50;
		setBounds(inset, inset,
                  screenSize.width  - inset*2,
                  screenSize.height - inset*2);
		//view_width = screenSize.width  - inset*2-10; 
		view_height = screenSize.height - inset*2-10; 
		view_width = view_height; 
		desktop = new JDesktopPane();
		setContentPane(desktop);
		JMenuBar menubar = create_menubar();
		setJMenuBar(menubar);
		desktop.setBackground(Color.WHITE);
		desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); 
	}
	public void createTopicFrame(String title, int w, int h, int y){
		tframe = new TopicFrame(title, w, h, y); 
		tframe.setVisible(true);
		tframe.setBackground(Color.LIGHT_GRAY);
		desktop.add(tframe);
	}
	private JMenuBar create_menubar(){
		JMenuBar menubar = new JMenuBar();
		JMenu file = new JMenu("File");
		JMenuItem f1 = new JMenuItem("Report_2009");
		f1.addActionListener(this); 
		file.add(f1);
		JMenuItem f2 = new JMenuItem("Report_2010");
		f2.addActionListener(this); 
		file.add(f2);
		JMenuItem f3 = new JMenuItem("Report_2011");
		f3.addActionListener(this); 
		file.add(f3); 
		JMenuItem f4 = new JMenuItem("Report_2012");
		f4.addActionListener(this); 
		file.add(f4); 
		JMenu help = new JMenu("Help");
		JMenuItem about = new JMenuItem("About"); 
		help.add(about); 
		menubar.add(file);
		menubar.add(help);
		return menubar;
	}
	public void actionPerformed(ActionEvent e){
		if(e.getActionCommand().equals("Report_2009")){
			System.out.println("Create Report: Health 2008"); 
			createTopicFrame("Health 2008", view_width, view_height, 2008); 
			} 
		else if(e.getActionCommand().equals("Report_2010")){
			System.out.println("Create Report: Health 2009");  
			createTopicFrame("Health 2009", view_width, view_height, 2009);
				} 
		else if (e.getActionCommand().equals("Report_2011")){
			System.out.println("Create Report: Health 2010"); 
			createTopicFrame("Health 2010", view_width, view_height, 2010);
			}
		else if (e.getActionCommand().equals("Report_2012")){
			System.out.println("Create Report: Health 2011"); 
			createTopicFrame("Health 2011", view_width, view_height, 2011);
			}
	}
	public static void main(String[]args){
		JFrame.setDefaultLookAndFeelDecorated(true);
		Window window = new Window();
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setVisible(true);
	}
}
